<?php

include 'config.php';

error_reporting(E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if ($post) 
   {
   include 'functions.php';

   $name = stripslashes($_POST['name']);
   $email = trim($_POST['email']);
   $subject = stripslashes($_POST['subject']);
   $message = stripslashes($_POST['message']);
   $por = "- www.milosmilojkovic.com";

   $error = '';

   // Check name

   if (!$name) 
   {
      $error .= 'Please enter your name.<br />';
   }

   // Check email

   elseif (!$email) 
   {
      $error .= 'Please enter an e-mail address.<br />';
   }

   elseif ($email && !ValidateEmail($email)) 
   {
      $error .= 'Please enter a valid e-mail address.<br />';
   }

   // Check message (length)

   elseif (!$message || strlen($message) < 15) 
   {
      $error .= "Please enter your message. It should have at least 15 characters.<br />";
   }


   if (!$error) 
   {
       $mail = mail(WEBMASTER_EMAIL, $subject, $message, "From: " . $name . "  " . $por . " <" . $email . ">\r\n"
               . "Reply-To: " . $email . "\r\n"
               . "X-Mailer: PHP/" . phpversion());

       if ($mail) 
       {
          echo 'OK';
       }
    }
    else 
    {
       echo '<div class="notification_error">' . $error . '</div>';
    }
}
?>